package netty.demo.nio.byteBuffer;

import java.nio.ByteBuffer;

/**
 * @author Zed
 * @description
 * @date 2022/10/20 22:52
 */
public class testByteBufferMark {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        byteBuffer.put(new byte[]{'a', 'b', 'c', 'd'});
        byteBuffer.flip();
        //mark&&reset
        //mark做标记，记录position位置，reset将position重置到mark位置
        System.out.println((char) byteBuffer.get());//position 0
        System.out.println((char) byteBuffer.get());//position 1
        byteBuffer.mark();//加标记，索引2的位置
        System.out.println((char) byteBuffer.get());
        System.out.println((char) byteBuffer.get());
        byteBuffer.reset();//将position重置到索引2
        System.out.println("-----将position重置到索引2-----");
        System.out.println((char) byteBuffer.get());
        System.out.println((char) byteBuffer.get());
    }
}
